home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: undoMarkLargeObjOnPage.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:03 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "latch.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "log.h"
- #include "volume.h"
- #include "logrecs.h"
- #include "openlog.h"
- #include "trans.h"
- #include "bitmap.h"
- #include "file.h"
- #include "consist.h"
- #include "undo.h"
- #include "io_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "bm_extfuncs.h"
- #include "log_extfuncs.h"
- #include "undo_extfuncs.h"
- #include "logaction.h"
- #include "util_funcs.h"
- #include "thread_globals.h"
- #include "bf_globals.h"
-
-
- void
- undoMarkLargeObjOnPage (
-
- LOGRECORDHDR *recordHeader
- )
- {
-
- VOLREC *volRec;
- PID *pid;
- FOUR *markLoc;
- SHORTPID *key;
- NODEPAGE *nodePage;
- GROUPLINK *nodeLink;
- LOGRECORDINFO recordInfo;
- FORCEMARK forceMark;
- LSN lsn;
- SHORTPID *gotPid;
- LRC *lrc;
- int i;
- FOUR foundLoc;
-
- TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
-
- /*
- * get a pointer to the pid in the record
- */
- pid = (PID *) &(recordHeader->actionPid);
- TRPRINT(TR_IO, TR_LEVEL_2, ("pid:%d", pid->page));
-
- /*
- * get a pointer to the mark location in the record
- */
- markLoc = (FOUR *) GET_LOG_IMAGE(recordHeader, 0);
- TRPRINT(TR_IO, TR_LEVEL_2, ("markLoc:%d", *markLoc));
-
- /*
- * get a pointer to the key in the record
- */
- key = (SHORTPID *) GET_LOG_IMAGE(recordHeader, 1);
- TRPRINT(TR_IO, TR_LEVEL_2, ("key:%d", *key));
-
- /*
- * check to see if the volume is mounted
- */
- if ((volRec = io_FindVolRec(pid->volid)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * Read in first page of file and grab node type
- */
- if ((nodeLink = bf_ReadPage(UserBufGroup, pid, FILE_PAGE2SIZE, BF_SEM)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * get a pointer to the node page and the key
- */
- nodePage = (NODEPAGE *) nodeLink->bufFrame;
- gotPid = &(nodePage->contents.keyPid.allKeys[*markLoc].key);
-
- /*
- * The markLoc may not be correct if other pages have been
- * inserted/deleted from the file. So, search up first
- * (since most likely and insert occurred), and then back.
- */
- if ( (*gotPid & LARGEMASK) != *key) {
- foundLoc = -1;
- /* search up */
- for(i = (int)(*markLoc)+1; i < nodePage->header.nodeCount; i++) {
- if ( (nodePage->contents.keyPid.allKeys[i].key & LARGEMASK) == *key) {
- foundLoc = i;
- break;
- }
- }
- if (foundLoc == -1) {
- /* now search down */
- for( i = (int)(*markLoc)-1; i >= 0; i--) {
- if ( (nodePage->contents.keyPid.allKeys[i].key & LARGEMASK) == *key) {
- foundLoc = i;
- break;
- }
- }
- }
-
- if (foundLoc == -1) {
- /*
- * The key was not found. Ideally we should search
- * the tree for the key since the undo is really a
- * logical operation. But, at this time we just
- * don't undo it. This is safe but could lead
- * to inefficiency in destroying the file. But,
- * this problem can realistically only occur when
- * loading a large file (in one transaction) and
- * in that case the page will likely be deallocated in
- * the event of an abort.
- */
- /*SM_ERROR(TYPE_FATAL, esmINTERNAL);*/
-
- signalSemaphore( &(nodeLink->pageHash->semaphore) );
- bf_UnfixPage(nodeLink, BF_DEFAULT, FALSE);
- return;
- }
- markLoc = &foundLoc;
- gotPid = &(nodePage->contents.keyPid.allKeys[*markLoc].key);
- }
-
- /*
- * remove the mark
- */
- *gotPid &= ~SETLARGE;
-
- /*
- * increment the lrc on the page
- */
- lrc = &(((NODEHEADER *) nodeLink->bufFrame)->lrc);
- INCREMENT_LRC(lrc);
-
- /*
- * initialize the log information
- */
- recordInfo.type = LOG_REC_TYPE_COMPENSATION;
- recordInfo.action = LOG_ACTION_NO_LARGE_OBJ_ON_PAGE;
- recordInfo.imageCount = 2;
- recordInfo.actionPid = pid;
- recordInfo.actionLRC = lrc;
- recordInfo.imageSize[0] = sizeof(FOUR);
- recordInfo.imageData[0] = (VOID *) markLoc;
- recordInfo.imageSize[1] = sizeof(SHORTPID);
- recordInfo.imageData[1] = (VOID *) key;
- recordInfo.flags = NOFLAGS;
- recordInfo.nextUndoLSN = recordHeader->previousLSN;
-
- /*
- * write the record to the log
- */
- if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec,
- &recordInfo, &lsn, NOFLAGS)) < 0) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * mark the page dependency
- */
- DEPEND_LOG(nodeLink->pageHash, forceMark, &lsn, lrc);
-
- /*
- * release the page semaphore
- */
- signalSemaphore( &(nodeLink->pageHash->semaphore) );
-
- /*
- * release and dirty the page
- */
- bf_UnfixPage(nodeLink, BF_DEFAULT, TRUE);
- }
-